package cn.wostore.wxhelper.Xposed;

import android.content.Intent;
import android.view.MenuItem;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;

/**
 * @author wuch
 * @date 2018/12/19 0019
 */
public class StartMainActivityHook extends XC_MethodHook {
    private final LoadHook loadHook;

    StartMainActivityHook(LoadHook loadHook) {
        this.loadHook = loadHook;
    }

    @Override
    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
        super.beforeHookedMethod(param);
        MenuItem menuItem = (MenuItem) param.args[0];
        XposedBridge.log(menuItem.getItemId() + menuItem.getTitle().toString());
        if (menuItem.getItemId() == 4) {
            Intent intent = new Intent();
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setAction(Intent.ACTION_MAIN);
            intent.setClassName(loadHook.info.PROJECT_NAME, loadHook.info.PROJECT_NAME + ".MainActivity");
            loadHook.launcherUI.startActivity(intent);
        }
    }
}
